// 导入用户集合
const { Banner } = require('../../../model/banner');
// 引入分页模块
const pagination = require('mongoose-sex-page')

module.exports = async (req, res) => {
  let banners = []
  if (!req.query.pageIndex) {
      // 全部
      banners = await Banner.find().sort({_id: -1})
  } else {
      const { pageIndex, pageSize } = req.query
      // 分页
      banners = await pagination(Banner).find().sort({_id: -1}).page(pageIndex).size(pageSize).exec()
  }
  res.json({
      data: banners
  })
}